package com.aviation.sell_ticket.tool;

import cn.hutool.core.date.DateUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.AlgorithmMismatchException;
import com.auth0.jwt.exceptions.InvalidClaimException;
import com.auth0.jwt.exceptions.SignatureVerificationException;
import com.auth0.jwt.exceptions.TokenExpiredException;
import com.auth0.jwt.interfaces.DecodedJWT;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;
@Component
public class Jwt {

    @Value("jwt.secretKey")
    private String secretKey;

    public String getToken(String userId){
        return JWT.create().withAudience(userId)
                .withClaim("user_idHMAC256",userId)
                .sign(Algorithm.HMAC256(secretKey));
    }

    public DecodedJWT jwtVerify(String token){
        DecodedJWT verify=null;
        try {
            verify = JWT.require(Algorithm.HMAC256(secretKey)).build().verify(token);
        } catch (Exception e){
            return null;
        }
        return verify;
    }


}
